package org.bluedream.core.module.service.bill.stkIn.dtl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.commons.collections.map.HashedMap;
import org.bluedream.comm.utils.EmptyUtil;
import org.bluedream.core.module.base.BillDtlServiceImpl;
import org.bluedream.core.module.dao.bill.stkIn.dtl.StkInBackDtlDao;
import org.bluedream.core.module.entity.bill.stkIn.StkInBack;
import org.bluedream.core.module.entity.bill.stkIn.dtl.StkInBackDtl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.Map;

/**
 * @ClassName StkInBackDtlService
 * @Description TODO
 * @Author foxsand
 * @Data 2021-11-18 15:25
 * @Version
 */
@Service
@DS("master")
@Transactional(
        readOnly = true
)
public class StkInBackDtlService extends BillDtlServiceImpl<StkInBackDtlDao, StkInBackDtl> implements IService<StkInBackDtl> {
    private static final Logger logger = LoggerFactory.getLogger(StkInBackDtlService.class);

    @Override
    public StkInBackDtl getById(Serializable id) {
        if (EmptyUtil.isEmpty(id)){
            return new StkInBackDtl();
        }
        return super.getById(id);
    }

    public IPage<StkInBackDtl> findPage(StkInBack head , String... args) {
        if (EmptyUtil.isEmpty(head.getBillNum())){
            return null;
        }else {
            StkInBackDtl entity = new StkInBackDtl(head.getBillNum());
            Map<String , Object> search = null;
            search = new HashedMap();
            search.put("stkInBackDtl.bill_type" , head.getBillType());
            search.put("stkInBackDtl.bill_num;eq" , entity.getBillNum());
            entity.setLimit((long) super.getListBySearch(entity , "bill_num" , entity.getBillNum()).size());
            entity.setPage(1L);
            IPage<StkInBackDtl> page = super.findPage(entity , search , args);
            return page;
        }
    }
}
